package cn.net.cfss.fgbp.face.console.controller;

import cn.net.cfss.fgbp.api.console.inte.ISysAppMenuService;
import cn.net.cfss.fgbp.api.console.vo.SysAppMenuVo;
import cn.net.cfss.fgbp.base.constant.ErrCodeEnum;
import cn.net.cfss.fgbp.base.controller.BaseController;
import cn.net.cfss.fgbp.face.console.util.ReturnUtil;
import cn.net.cfss.fgbp.face.console.vo.BaseParas;
import cn.net.cfss.fgbp.log.influxdb.ApiDto;
import cn.net.cfss.fgbp.log.statistics.IStatsdLogService;
import cn.net.cfss.fgbp.log.statistics.LogDtoFactory;
import cn.net.cfss.fgbp.log.util.LogStandardUtil;
import com.alibaba.fastjson.JSONObject;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.UUID;

/**
 * @author oygq
 * @title: SysAppMenuController
 * @description: TODO
 * @date 2019/4/8 15:28
 */
@RestController
@Slf4j
@RequestMapping("console/appMenu")
public class SysAppMenuController extends BaseController {

    @Autowired
    ISysAppMenuService sysAppMenuService;

    @ApiOperation("应用菜单新增")
    @RequestMapping(value = "/add", method = RequestMethod.POST)
    public String inset(@RequestBody BaseParas paras){
        SysAppMenuVo vo = JSONObject.toJavaObject(paras.getPlain(),SysAppMenuVo.class);
        if(sysAppMenuService.insert(vo)){
            return ReturnUtil.returnSucc();
        }
        return ReturnUtil.returnErr(ErrCodeEnum.ERR);
    }

    @ApiOperation("应用菜单修改")
    @RequestMapping(value = "/edit", method = RequestMethod.POST)
    public String update(@RequestBody BaseParas paras){
        SysAppMenuVo vo = JSONObject.toJavaObject(paras.getPlain(),SysAppMenuVo.class);
        if(sysAppMenuService.update(vo)){
            return ReturnUtil.returnSucc();
        }
        return ReturnUtil.returnErr(ErrCodeEnum.ERR);
    }

    @ApiOperation("应用菜单删除")
    @RequestMapping(value = "/delete/{appMenuId}", method = RequestMethod.POST)
    public String update(@PathVariable String appMenuId){
        if(StringUtils.isBlank(appMenuId)){
            return ReturnUtil.returnErr("角色按钮为空");
        }
        if(sysAppMenuService.delete(appMenuId)){
            return ReturnUtil.returnSucc();
        }
        return ReturnUtil.returnErr(ErrCodeEnum.ERR);
    }

    @ApiOperation("应用菜单批量删除")
    @RequestMapping(value = "/deleteBatch", method = RequestMethod.POST)
    public String deleteBatch(@RequestBody BaseParas paras){
        List<String> appMenuIds = (List<String>) paras.getPlain().get("appMenuIds");
        if(sysAppMenuService.deleteBatch(appMenuIds.toArray(new String[appMenuIds.size()]))){
            return ReturnUtil.returnSucc();
        }
        return ReturnUtil.returnErr(ErrCodeEnum.ERR);
    }

    @ApiOperation("根据应用id查询菜单")
    @RequestMapping(value = "/query/{appId}", method = RequestMethod.POST)
    public String queryByList(@PathVariable String appId){
        List<String> menus = sysAppMenuService.queryByAppId(appId);
        return ReturnUtil.returnSucc(menus);
    }

    @ApiOperation("应用菜单删除")
    @RequestMapping(value = "/delete", method = RequestMethod.POST)
    public String deleteByMenus(@RequestBody BaseParas paras){
        SysAppMenuVo vo = JSONObject.toJavaObject(paras.getPlain(),SysAppMenuVo.class);
        if(sysAppMenuService.deleteByMenus(vo)){
            return ReturnUtil.returnSucc();
        }
        return ReturnUtil.returnErr(ErrCodeEnum.ERR);
    }
}
